package org.ilc.sample;

import org.ilc.Bootstrap;
import org.ilc.push.ISendListener;
import org.ilc.push.Message;

/**
 * Simple message send listener.
 * @author malb
 * Date: 13-4-12
 * Time: 下午3:00
 */
public class SimpleSendListener implements ISendListener {

    /**
     * Do something when messageSend event has been triggered.
     * This does not mean that the data has been sent to the client
     * @param message
     */
    @Override
    public void messageSened(Message message) {
        // 表示 已经处理过该消息
        if(Message.STATUS_SEND_SUCESSFUL.equals(message.getStatus())){
            //表示消息发送成功
        }else if(Message.STATUS_SEND_FAILUER.equals(message.getStatus())){
            //表示消息发送失败
//            System.out.println ("消息发送失败");
            //如果未过期
            if(!message.isExpired()){
//                System.out.println("消息未过期");
                //添加到 缓存 或者 其他操作
                Bootstrap.getContext ().getDataProvider ().store (message);
            } else {
//                System.out.println ("消息已过期");
            }
        }
    }

    /**
     * Handle exception when server is abnormal.
     * @param message
     * @param e
     */
    @Override
    public void onException(Message message, Exception e) {
//        System.out.println ("send msg faild.................");
        Bootstrap.getContext ().getDataProvider ().store (message);
    }
}
